Repository navigation
fix(studio): a cropped layer's outline is cut at the layer's own scale, sealed or not - #8496
Conversation
…rries its layout size
Edit accuracy: accurate 271 (base branch 271), smooth 54 of thoseThe gate passes. Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Requesting changes at 2d95ec27. The scaled case is fixed, but rotated cropped layers get a deeper wrong cut in two places.
Blocker: snap targets and marquee hit tests on rotated cropped layers.
hugScale(domEditOverlayCrop.ts) divides the rect's width bylayout.width.frameRectToOverlaynow attacheslayoutto the axis-aligned box, both intoOverlayRect(unsealed) and inbaseRect(sealed).- For a rotated layer, that box is its bounding box, so the ratio picks up the turn as if it were scale.
- Two paths hug that axis-aligned box:
toVisibleOverlayRect, used bysnapTargetCollection.tsandmarqueeCommit.ts:91;flatVisibleRect, used bypreviewGestureStartRead.ts:87for snap boxes andpreviewOverlayRects.ts:133.
- Probe, run through
hugRectForClipPathdirectly: a 200×200 layer turned 45° at zoom 1, withinset(0 100px 0 0). Its bounding box is 282.8 wide.- Main (zoom only) hugs to 182.8.
- This head (with
layout) hugs to 141.4. - The visible half's real bounding-box width is 212.1.
- So snap edges and marquee hits now cut roughly a third of the visible part away, where main cut a seventh.
- The body says "a rotated cropped layer's outline (its box is the rotated one, cut the same way as before)". That holds for the oriented paths (
orientOverlayRectmeasures width from the corners), but not for these axis-aligned ones. - Suggested fix, smallest first:
- attach
layoutonly where the rect's width is the layer's own edge: inorientOverlayRect, or inframeRectToOverlayonly when the box'sangleis 0; - or have
hugScaleuse the corner edge lengths when there are corners.
- attach
- Please add a test row with a turned layer for
flatVisibleRectandtoVisibleOverlayRect.
What I checked and found fine
- The scaled case. Shown size over own size covers the layer's own scale and any ancestor scale.
offsetWidthand the bounding rect are both border-box, which is whatinset()is measured from. - Fallbacks. SVG children (
offsetWidthundefined → 0), unions and member rects (nolayout) fall back to the zoom. layoutis checked on both sides. InwatchGeometryit must have exactly the keyswidth,height, each finite and within 0..MAX_DRAFT_PX. InpreviewElementsit is now part ofisBox.gesture-startreads it fromboxOfinstead of keeping its own copy, andMAX_DRAFT_PXmoving toeditingElement.tskeeps the stream module offeditingPort.ts.useCropOverlay. It now derives its inset fromhugRectForElement. Thehug !== overlayRectidentity check is right, becausehugRectForClipPathreturns the same rect when there is no crop.- Red first. With main's product code under the new tests,
previewOverlayRects"cuts a scaled layer's crop at its own scale…" and bothuseCropOverlay"twice its own size" rows fail. - Tests at this head: core
watchGeometry,editingGeometry,editingGestureStartandeditingPortpass 42/42. Studio overlay, crop, geometry, preview-elements, marquee and off-canvas files pass 107/107.
Need: yes · Size: ok · Reuse: good (useCropOverlay drops its copy of the arithmetic, one layout source) · Simpler: yes · Structure: fine
Risk: medium. Every hugged outline goes through the new scale, including the axis-aligned rects of rotated layers.
— Rames (hf-review)
jrusso1020
left a comment
There was a problem hiding this comment.
Approve at f67c979d. The blocker from my last review is fixed.
Need ✅ · Size ✅ · Reuse ✅ (elementCornerPoints, cornerEdgeLength, one hugRectForClipPath) · Simpler ✅ · Structure ✅
Risk: low. The change touches only the overlay drawing, and a layer with no known size falls back to the zoom as before.
Blocker resolved: rotation is no longer counted as scale. The crop is now scaled by overlay px per CSS px along the layer's own edges:
- Sealed:
ownScaleOftakes the corner edge lengths overlayout. - Unsealed:
liveOwnScalereads the live element, and only when it has a crop to cut. On an oriented rect it divides the rect's own size by itsoffset*size. On a box aligned to the screen axes it divides the corner edges bygetBoundingClientRectand scales that back to the overlay. Both come out in overlay px per CSS px.
What I checked:
- Fails without the fix: I put the three product files back to the previous head
2d95ec27. The new turned-layer test fails (expected 167.40 to be close to 173.21), and so do bothuseCropOverlayrows. - At the head: 74/74 pass across
previewOverlayRects,useCropOverlayand thedomEditOverlay*tests.tsc --noEmitin studio is clean, andmerge-treeagainst current main is clean.
Note (P2, already true on main, not this PR): for a turned layer, a box aligned to the screen axes is cut along screen axes by the crop scaled to the layer's own edges. The hover, snap and marquee boxes therefore come out a little narrower than the true box around the visible part. For a 45° 200×200 layer cut by inset(0 100px 0 0), the box is about 183 wide against a true 212, the same as main. The selection outline uses the oriented rect and is exact. A follow-up could cut the oriented rect first and then take its box.
— Rames (hf-review)
…ne-scale # Conflicts: # packages/core/src/runtime/editingGestureStart.ts # packages/studio/src/player/lib/previewElements.ts
jrusso1020
left a comment
There was a problem hiding this comment.
Re-stamp at 6289e60e (merge of main into f67c979d, which I approved earlier).
Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. The only changes since my last approval are the two conflict resolutions.
- Parents:
f67c979dand main45674e84. Runninggit merge-treeon those two conflicts in exactlyeditingGestureStart.tsandpreviewElements.ts. All other files merge on their own. editingGestureStart.ts: keeps this PR'sgeometry.layout(no separatelayoutfield, andmeasureGrowResponse(element, geometry.layout)) and keeps main'srotation/cssRotationread. Nothing still reads the droppedlayoutfield.previewElements.ts:isLayoutstays insideisBox(this PR), andreadGestureStartkeeps main'scssRotationdestructure and itskept(..., isCssRotation(...))check.- Checks:
tscis clean for core and studio. Core editing tests: 422 pass. Studio overlay, crop and player/lib tests: 403 pass.
— Rames (hf-review)
What
A cropped layer that is scaled (by GSAP or CSS) now has its outlines cut at its visible edge, in a sealed preview and an unsealed one alike. This covers its outline in a group, as a child outline, in the hover and snap and marquee boxes, and the selection box's crop hug. Before, every one of these cut the crop at the editor's zoom alone, so a layer scaled up by 1.25 had its outline drawn past its visible edge, and one scaled down had it drawn short.
Why
A crop (
clip-path: inset(...)) is in the layer's own CSS px, before its transform. To draw it on screen, Studio has to scale it by everything between the layer and the screen, the layer's own scale included. The one function that cut outlines to a crop (hugRectForClipPath) used the editor zoom only, anduseCropOverlaykept its own copy of the same arithmetic.In an unsealed preview Studio could read the layer's size from the element. In a sealed one it could not: the frame's geometry reply carried only the layer's on-screen box.
Related work
Follows #8468 (merged: the same layer's resize corners after a sealed Layers pick) and #8451 (the crop frame's insets at the layer's scale). #8451's press and selection read of the layer's size (
gesture-start) could later come from this geometry reply instead.How
editingGeometry.ts): each geometry box carries the layer's own size,layout(offsetWidth/offsetHeight, 0 where there is none).gesture-startalready sent that value and now takes it from the sameboxOf, so there is one copy.previewOverlayRects.ts, carried asownScale).liveOwnScale), so hover and snap rects of uncropped layers measure nothing extra.hugRectForClipPathfalls back to the zoom when the scale is unknown, as for a union of several layers.useCropOverlaynow uses it rather than its own arithmetic.previewElementscheckslayouton every box;gesture-startno longer checks it separately.watchGeometry.ts): the per-frame geometry stream parses each element against an exact field list. Withoutlayoutin that list, every streamed element from the frame would be refused now that geometry carries it. The list takeslayoutwith exact keys and each side a finite number from 0 toMAX_DRAFT_PX, the bound Studio's own geometry reader uses.MAX_DRAFT_PXmoves toeditingElement.tsbeside the other shared limits (the stream module cannot importeditingPort.ts, which imports it);editingPort.tsre-exports it.Before
A cropped layer (
clip-path: inset(0 150px 0 0)) that GSAP scales to 1.25, grouped with a plain square, in a sealed preview atmain. The yellow layer's outline and the group box run past its visible right edge.After
The same, with this change: the outline and the group box stop at the visible edge, sealed and unsealed alike.
Test plan
packages/studio/src/components/editor/previewOverlayRects.test.ts("cuts a scaled layer's crop at its own scale, the same in both"). It checks a layer shown at twice its own size, through a scriptable frame and through a sealed one running the real editing agent. With main's product code under the new tests, it fails: the member is not the 150 px wide its own scale makes it.packages/studio/src/hooks/useCropOverlay.test.ts("a layer shown at twice its own size hugs its crop at that scale", sealed and unsealed). With main's product code:expected 150 to be 300.packages/core/src/runtime/editing/watchGeometry.test.ts("takes what the frame measures, and a gone element as null"): with the geometry change but not the stream's, a measured element is refused (expected null). Refusal rows were added for a malformedlayout: negative, over the bound, a string, an extra key, and missing.tsc --noEmitin core and studio, Fallow and pre-push are clean.mainsealed; this branch at d395ca39, sealed and unsealed; sealed confirmed by the frame's originnull), the walk above. The layer measures 300 px on screen for 240 of its own, so its visible part is 113 frame px, 19.6 overlay px at that zoom. Its outline in the group is 26 px wide atmainsealed and 19 px with this change in both modes. The captures were taken at d395ca39; the same walk at f67c979 (the scale from the layer's own edges) measures the same 19 px in both modes.previewOverlayRects.test.ts("cuts a turned, scaled layer's crop at its own scale, not its upright box's, the same in both"): a layer turned 30 degrees and scaled 2x with a 50 px right crop. Scaling by its upright box cut 167.4 px wide where its own edges make 173.2 (expected 167.40 to be close to 173.21).Not exercised: macOS and Safari (Chrome on Linux only); a turned cropped layer in real Studio (covered by the test above through both kinds of frame); an SVG child, whose size reads 0 and falls back to the zoom as before.